#coding=UTF-8
import requests
import json

# 引入自定义的keystone模块
import keystone
keystone_s=keystone.getToken()

#nova(compute)端点地址：
subnetwork_url="http://192.168.100.10:9696/v2.0/subnets/"
#定义请求头
headers={
    "X-Auth-Token":keystone_s['token'],
    "Content-Type": "application/json"
}

#定义请求主题
body={
	"subnet": {
		"name": "net-sub-1",
		"network_id": "9ea4840a-8214-4cda-9c9f-d69e28857820",
		"ip_version": 4,
		"gateway_ip": "192.168.201.1",
		"cidr": "192.168.201.0/24"
	}
}

#发送请求
req=requests.post(subnetwork_url,headers=headers,data=json.dumps(body))
#格式化打印响应
print(json.dumps(req.json(),sort_keys=True,indent=4))

#
# #循环打印主机列表
# for i in req.json()['servers']:
#     print("server name:",str(i['name']),"id:",str(i['id']))